package com.lsw.util;

import java.security.MessageDigest;

/**
 * MD5工具类
 * 
 * @author dada
 */
public class Md5Util {

	public static String md5(String data) {
		try {
			byte defaultBytes[] = data.getBytes();
			MessageDigest algorithm = MessageDigest.getInstance("MD5");
			algorithm.reset();
			algorithm.update(defaultBytes);
			byte messageDigest[] = algorithm.digest();

			StringBuffer hexString = new StringBuffer();
			for (byte aMessageDigest : messageDigest) {
				int val = 0xff & aMessageDigest;
				if (val < 16)
					hexString.append("0");
				hexString.append(Integer.toHexString(val));
			}
			return hexString.toString();
		} catch (Exception e) {
			System.err.println(e.toString());
		}
		return null;
	}
}
